<?

		$sql['order'] = "grid_reference asc, ".$sql['order'];
		
		$opt['has_hidden'] = true;
		
		if (strpos($sql['columns'], ",grid_reference") === FALSE) {
			$sql['columns'] .= ",grid_reference";
		} 
		function searchbreak(&$c,$start='',$end='') {
			static $last;
			static $count;
			static $hidden;

			if (empty($c)) {//its the last one
				if ($last) {
					print $end;
					if ($hidden) {
						print "($hidden hidden images - <a href=\"".linktoself(array('myriad'=>$last,'delete'=>array('opt','page')))."\">view all in $last</a>)";
					} else {
						?>
						<script>
						if (document.getElementById('f<? echo $last; ?>')) {
							document.getElementById('f<? echo $last; ?>').style.display = 'none';
						}
						</script>
						<?
					}
				}
				return;
			}
			
			$gridref = substr($c['grid_reference'],0,strlen($c['grid_reference'])-4);
			
			if ($gridref != $last) {
				if ($last) {
					print $end;
					if ($hidden) {
						print "($hidden hidden images - <a href=\"".linktoself(array('myriad'=>$last,'delete'=>array('opt','page')))."\">view all in $last</a>)";
					} else {
						?>
						<script>
						if (document.getElementById('f<? echo $last; ?>')) {
							document.getElementById('f<? echo $last; ?>').style.display = 'none';
						}
						</script>
						<?
					}
				}
				
				print "<h4>Gridsquare $gridref";
				if (empty($_GET['taken']) || $_GET['taken'] != $gridref) 
					print " <span id=\"f$gridref\">(<a href=\"".linktoself(array('myriad'=>$gridref,'delete'=>array('opt','page')))."\">Show only</a>)</span>";
				print "</h4>";
				print $start;
				$count = 1;
				$hidden =0;
			} else {
				$count++;
				if ($count > 4) {
					$GLOBALS['opt']['has_hidden'] = true;
					$GLOBALS['resultCount']--;
					$hidden++;
					return false;
				}
			}
			
			$last = $gridref;
			return true; //we dont disable any images...
		}
		
		$opt['opt'] = 'myriad';
